-
Notifications
You must be signed in to change notification settings - Fork 409
add support for importing typescript types and deduping imports #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
node dist/src/cli.js --mirrorDir --declareExternallyReferenced false --outDir=qwer -i test/resources/mirror-dir/ReferencingType.json --cwd test/resources/mirror-dir -o foo.ts
…eferenced false -i test/resources/mirror-dir/ -o mirrorDir
There's some cleanup I need to do here--I left some debugging things in place. I'd welcome thoughts on if this makes sense in the meantime. |
|
||
if (dereferencedName) { | ||
dereferencedPaths.delete(schema) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems less than ideal. I need this elsewhere, and I'm wondering if there's a more natural way to register the source path for this schema without needing to keep all references in this map.
Cleaned it up. Still not sure this is the best implementation of this approach, but here is a stab. |
Overview
Issue #258 requests a way to deduplicate imports.
I’m unsure how others are avoiding this problem today—pointers welcome—but here’s a concrete approach I’ve implemented.
This PR adds a
--useTypeImports
flag that enables deduplication when targeting a directory. It generates a mirrored output structure, and replaces inline definitions withimport type
statements based on$ref
paths.Instead of:
You get:
Approach
This supports setups where a directory of JSON Schema files reference each other via $ref. For example:
Running:
...currently inlines all referenced types, leading to duplication. You'll see something like:
With the new flag, you can run:
...and you will get:
Any comments on this approach / implementation welcome, of course.